<?php

class ContactUsForm extends reCaptchaForm {
  public function configure() {

    $this->setWidget('name', new sfWidgetFormInput());
    $this->setWidget('email',new sfWidgetFormInput());
    $this->setWidget('phone', new sfWidgetFormInput());
    $this->setwidget('body', new sfWidgetFormTextarea());

    $this->setValidator('name',new sfValidatorString(array('required' => true)));
    $this->setValidator('email',new sfValidatorEmail(array('required'=>true), array('invalid' => 'Email address is invalid.')));
    $this->setValidator('phone',new sfValidatorString(array('required' => true)));
    $this->setValidator('body', new sfValidatorString(array('min_length' => 4),
            array(
                    'required'   => 'The message field is required',
                    'min_length' => 'The message "%value%" is too short. It must be of %min_length% characters at least.',
    )));
    $this->widgetSchema['body']->setLabel('Enquiry');

    if (sfConfig::get('app_recaptcha_active', false)) {
      $this->setWidget('response', new sfWidgetFormInput());
      $this->validatorSchema->setPostValidator(
              new sfValidatorSchemaReCaptcha('challenge', 'response')
      );
      $this->validatorSchema->setOption('allow_extra_fields', true);
      $this->validatorSchema->setOption('filter_extra_fields', false);
    }
    parent::configure();
  }
}
